package cn.wizzer.app.user.modules.models;

import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.integration.json4excel.annotation.J4EIgnore;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author zl
 * @date 2020/6/17 9:34
 */
@Data
@Table("user_account_record_statistics")
@Comment("用户流水统计")
@TableIndexes({@Index(name = "INDEX_CT_AT", fields = {"ctAt"}, unique = false)})
public class UserAccountRecordStatistics extends BaseModel implements Serializable {

    @Column
    @Name
    @Comment("ID")
    @J4EIgnore
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(uu32 = true)
    private String id;

    @Column
    @Comment("日期")
    @ColDefine(type = ColType.VARCHAR, width = 16)
    private String date;

    @Column
    @Comment("用户ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String userId;

    @Column
    @Comment("充值")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal recharge;

    @Column
    @Comment("转出")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal cash;

    @Column
    @Comment("礼物支出")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal giftOrder;

    @Column
    @Comment("礼物收入")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal giftIncome;

    @Column
    @Comment("系统礼物收入 = 礼物支出 - 礼物收入")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal systemGiftIncome;

    @Column
    @Comment("球类下注")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal ballBet;

    @Column
    @Comment("球注撤销")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal ballRevert;

    @Column
    @Comment("球注结算")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal ballResult;

    @Column
    @Comment("自身返利")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal selfRebate;

    @Column
    @Comment("下级返水")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal subRebate;

    @Column
    @Comment("系统返水支出 = 自身返利 + 下级返水")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal systemRebatePay;

    @Column
    @Comment("游戏中心盈亏 = 球类下注 - 球注撤销 - 球注结算 - 系统返水支出")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal gameCenterIncome;

    @Column
    @Comment("兑换")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal exchange;

    @Column
    @Comment("兑换退还")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal exchangeBack;

    @Column
    @Comment("商品支出 = 兑换 - 兑换退还")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal goodsPay;

    @Column
    @Comment("转账")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal transfer;

    @Column
    @Comment("转账退还")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal transferCancel;

    @Column
    @Comment("收款")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal collect;

    @Column
    @Comment("购买观点")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal buyViewPoint;

    @Column
    @Comment("出售观点")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal sellViewPoint;

    @Column
    @Comment("观点退款")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal refundViewPoint;

    @Column
    @Comment("观点退还（重新结算）")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal returnViewPoint;

    @Column
    @Comment("系统观点收入 = 购买观点 - 出售观点 - 观点退款 + 观点退还")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal systemViewPointIncome;

    @Column
    @Comment("(活动)自身消费返利")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal activityCostRebate;

    @Column
    @Comment("(活动)邀请消费返利")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    @Default("0")
    private BigDecimal activityInviteRebate;

    @Column
    @Comment("创建时间")
    //Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    /**
     * 初始化流水统计
     *
     * @param userId
     * @param date
     * @return
     */
    public static UserAccountRecordStatistics init(String userId, String date) {
        UserAccountRecordStatistics userAccountRecordStatistics = new UserAccountRecordStatistics();
        userAccountRecordStatistics.setUserId(userId);
        userAccountRecordStatistics.setDate(date);
        return userAccountRecordStatistics;
    }

}
